

#import "FAMMinGoalViewController.h"

@interface FAMMinGoalViewController ()
@property (weak, nonatomic) IBOutlet UIButton *FAMLoseButton;
@property (weak, nonatomic) IBOutlet UIButton *FAMGainButton;
@property (weak, nonatomic) IBOutlet UIButton *FAMMaintainButton;
@property (nonatomic, strong)NSString *FAMGoal;
@end

@implementation FAMMinGoalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.FAMGoal = [FAMUserManger shareInstance].userModel.target_type;
}
- (IBAction)FAM_loseButtonClick:(UIButton *)sender {
    [self FAM_sender:sender otherOneButton:self.FAMGainButton otherTwoButton:self.FAMMaintainButton];
    self.FAMGoal = @"1";
}
- (IBAction)FAM_gainButtonClick:(UIButton *)sender {
    [self FAM_sender:sender otherOneButton:self.FAMLoseButton otherTwoButton:self.FAMMaintainButton];
    self.FAMGoal = @"2";
}
- (IBAction)FAM_maintainButtonClick:(UIButton *)sender {
    [self FAM_sender:sender otherOneButton:self.FAMLoseButton otherTwoButton:self.FAMGainButton];
    self.FAMGoal = @"3";
}
- (void)FAM_sender:(UIButton *)sender otherOneButton:(UIButton *)buttonOne otherTwoButton:(UIButton *)buttonTwo{
    [sender setSelected:YES];
    [buttonOne setSelected:NO];
    [buttonTwo setSelected:NO];
    sender.layer.borderColor = kBlackColor.CGColor;
    sender.layer.borderWidth = 2;
    buttonOne.layer.borderColor = kWhiteColor.CGColor;
    buttonOne.layer.borderWidth = 2;
    buttonTwo.layer.borderColor = kWhiteColor.CGColor;
    buttonTwo.layer.borderWidth = 2;
    
}
- (IBAction)FAMSaveButtonClick:(UIButton *)sender {
    if (self.FAMLoseButton.isSelected || self.FAMGainButton.isSelected || self.FAMMaintainButton.isSelected) {
        WeakSelf(self);
        [self showHudInKeyWindowWithHint:nil];
        [FAMHttpTool FAM_PutFoodmateUserdataWithParameters:[NSMutableDictionary dictionaryWithDictionary:@{@"data":@{@"target_type":self.FAMGoal}}] success:^(FAMFoodmateUserdataModel * _Nonnull model, NSString * _Nonnull msg) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf hideHudKeyWindow];
                [FAMUserManger shareInstance].userModel.target_type = weakSelf.FAMGoal;
                [[NSNotificationCenter defaultCenter] postNotificationName:@"FAMHomeLoadData" object:nil userInfo:nil];
                [weakSelf.navigationController popViewControllerAnimated:YES];
            });
        } failure:^(NSString * _Nonnull errorInfo) {
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf hideHudKeyWindow];
                [weakSelf showHint:errorInfo];
            });
        }];
    }else{
        [self showHint:@"Please select your goal"];
    }
}

@end
